$(document).ready(function() {

  
    
});


function showAddArt()
{ 
	return hs.htmlExpand(null, {contentId:'popup_add_art', headingText: 'Добавить артикул'});				
}

function showParamArt()
{ 
	return hs.htmlExpand(null, {contentId:'popup_add_param', headingText: 'Добавить параметр'});				
}

function addArt(obj)
{ 
	var art = $('input[name=art]:last').val();
	
	$('#arts_params tr:last').clone(true).insertAfter('#arts_params tr:last');

	$('#arts_params tr:last > td:first').html(art);
	$('#arts_params tr:last input[type=text]').val('')
	$('#arts_params tr:last input[type=text]').attr('name', art+'[]');
	
	hs.close(obj);
}


function addParam(obj)
{ 
	var param = $('input[name=param]:last').val();
	
	$('#arts_params tr').each(function(index){
		var art = $(this).find('td:first').html();
		if(index == 0) $(this).find('td:last').before('<td>'+param+'</td>');
    	else $(this).find('td:last').before('<td><input type="text" name="'+art+'[]"/></td>');
	});
	
	hs.close(obj);
}

function showProducts(id)
{		
	hs.htmlExpand(null, {objectType: 'ajax', headingText: 'Добавить продукты', width: 300, height:400, 
		src:'/products/ajax-load-products/id/'+id});
	
}

function prodClick(id_parent, id_child)
{
	if($('#prod'+id_child).hasClass('on'))
	{ 
		$('#prod'+id_child).removeClass('on');
		
		$.post('/products/ajax-remove-child',
				{
					id_parent: id_parent,
					id_child: id_child
				},
				function(data){ 
					if(data != 'OK') alert(data);			
				});
	}
	else
	{
		$('#prod'+id_child).addClass('on');
		
		$.post('/products/ajax-add-child',
				{
					id_parent: id_parent,
					id_child: id_child
				},
				function(data){ 
					if(data != 'OK') alert(data);			
				});
	}
}

function searchProd(id_parent, s)
{
	$.post('/products/ajax-search-products',
			{
				id_parent: id_parent,
				s: s
			},
			function(data){ 
				$('#table_list').html(data);			
			});
}
	
	